require.config({
	baseUrl: "/app",
});
require(["jquery", "ModelBase"], function($, ModelBase) {
    $(function() {
		///////////////////////////////////////////////////////
		// Utility functions.
		///////////////////////////////////////////////////////
		function before() { testModelBase = new ModelBase('testModelObject'); }
		function after() { page.append('&nbsp;<br/>'); testModelBase = null; }

		//////////////////////////////////////////////////////
        // Tests start here.
		//////////////////////////////////////////////////////
		var page, testModelBase;
		page = $('body');

		page.append("<h3>Testing ModelBase class</h3> <br/>");
		// Test contructor.
		page.append("Testing Constructor , should return [Object] typeof === ModelBase...");
		before();
		if (!(testModelBase instanceof ModelBase)) {
			page.append('<b>Failed to create!</b>');
		}
		else if (testModelBase instanceof ModelBase) {
			page.append('<i>Passed!</i>');			
		}
		after();
				

		page.append("Test name property. Should equal 'testModel'...");
		before();
		if (testModelBase.name !== 'testModelObject') {
			page.append('<b>Failed! Name returned "' + testModelBase.name + '"</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();		
		

		page.append("Test row property. Should equal -1, when in this unititalized state...");
		before();
		if (testModelBase.row !== -1) {
			page.append('<b>Failed! .row() returned "' + testModelBase.row + '"</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();		 	
		
		
		page.append("Test row property. Should equal -1, when in this unititalized state...");
		before();
		if (testModelBase.row !== -1) {
			page.append('<b>Failed! .row() returned "' + testModelBase.row + '"</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();

		page.append("Test dataError visibility. Should be invisible to outside callers, Like brother Jed...");
		before();
		if (typeof testModelBase.dataError !== 'undefined') {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();

		page.append("Test dataRecieved visibility. Should be invisible to outside callers, Like brother Jed...");
		before();
		if (typeof testModelBase.dataRecieved !== 'undefined') {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();

		page.append('Test "fetch()" method...');
		before();
		
		if ((testModelBase.fetch()) && (testModelBase.lastStatus.code !== 0) || (testModelBase.rowCount < 0))  {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();
		
		page.append('Test the "fields" object to ensure it is unitialized before the first nextRow()" method success...');
		before();
		testModelBase.fetch();
		if (typeof testModelBase.field !== 'undefined')  {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();
		

		page.append('Test "nextRow()" method success...');
		before();
		testModelBase.fetch();
		if (!(testModelBase.nextRow()))  {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();
		
		page.append('Test for presence of the "field" object, after nextRow()" method success...');
		before();
		
		testModelBase.fetch();
		testModelBase.nextRow()
		if (typeof testModelBase.field === 'undefined')  {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();
		
		page.append('Test for presence of the "id" item, as a number, in the "field" object, after nextRow()" method success...');
		before();
		testModelBase.fetch();
		testModelBase.nextRow()
		if (typeof testModelBase.field !== 'undefined')  {
			if (!(testModelBase.field.id  === 1))  {
				page.append('<b>Failed!</b>');
			}
			else {
				page.append('<i>Passed!</i>');			
			}
		}
		after();
		
		
		page.append('Test "nextRow()" method success on second, or multiple passes...');
		before();
		testModelBase.fetch();
		testModelBase.nextRow();
		if (!(testModelBase.nextRow()))  {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();
		
		page.append('Test for presence of the "field" object, after nextRow()" method success on second, or multiple passes...');
		before();
		
		testModelBase.fetch();
		testModelBase.nextRow();
		testModelBase.nextRow();
		if (typeof testModelBase.field === 'undefined')  {
			page.append('<b>Failed!</b>');
		}
		else {
			page.append('<i>Passed!</i>');			
		}
		after();
		
		page.append('Test for presence of the "id" item, in the "field" object, after nextRow()" method success on second, or multiple passes...');
		before();
		testModelBase.fetch();
		testModelBase.nextRow()
		testModelBase.nextRow()
		if (typeof testModelBase.field !== 'undefined')  {
			if (!(testModelBase.field.id  > 1))  {
				page.append('<b>Failed!</b>');
			}
			else {
				page.append('<i>Passed!</i>');			
			}
		}
		after();
				
		
    });

	
});









